﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Http;
using Jw.Models;
using Jw.Core;
using Jw.Web.Areas.Mms.Common;
using Newtonsoft.Json.Linq;
using Jw.Web.Areas.Pacm.Common;
using Jw.Web.App_Start;
namespace Jw.Web.Areas.Pacm.Controllers
{
    /// <summary>
    /// 动力计划指标
    /// </summary>
    public class DljhzbController : BaseController
    {
        //
        // GET: /Pacm/Dljhzb/

        public ActionResult Index()
        {
            return View();
        }

    }


    public class DljhzbApiController : ApiController
    {
        public string GetNewBillNo()
        {
            return new p_DljhzbService().GetNewKey("Dljhzb_BillNo", "dateplus");
        }
        // get api/Zzjhzb
        public IEnumerable<dynamic> GetAll()
        {
            var Service = new p_DljhzbService();
            var pQuery = ParamQuery.Instance().Select("*").From("p_Dljhzb").OrderBy("Dljhzb_BillNo");
            var result = Service.GetDynamicList(pQuery);
            return result;

        }

        [System.Web.Http.HttpPost]
        public void Edit(dynamic data)
        {
            var listWrapper = RequestWrapper.Instance().LoadSettingXmlString(@"
        <settings>
            <table>
                p_Dljhzb
            </table>
            <where>
                <field name='Dljhzb_BillNo' cp='equal' ></field>
            </where>
        </settings>"
              );

            var service = new p_DljhzbService();
            var result = service.Edit(null, listWrapper, data);

        }

        public void Delete(string id)
        {
            var result = new p_DljhzbService().Delete(ParamDelete.Instance().AndWhere("Dljhzb_BillNo", id));
            MmsHelper.ThrowHttpExceptionWhen(result <= 0, "单据删除失败[Dljhzb_BillNo={0}]，请重试或联系管理员！", id);
        }

        //审核
        [System.Web.Http.HttpPost]
        public void Audit(string id, JObject data)
        {
            var status = data["status"].ToString();
            var comment = data["comment"].ToString();
            var result = new PacmService().Audit(typeof(p_Dljhzb).Name, "Dljhzb_BillNo", id, status, comment);
            MmsHelper.ThrowHttpExceptionWhen(result < 0, "单据审核失败[Dljhzb_BillNo={0}]，请重试或联系管理员！", id);
        }

    }
}
